Scrape Trustpilot Reviews to Google Sheets
工作流概述
这是一个包含13个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "DqvkhR9nzoPQKxGh",
"meta": {
"instanceId": "e634e668fe1fc93a75c4f2a7fc0dad807ca318b79654157eadb9578496acbc76"
},
"name": "Scrape Trustpilot Reviews to Google Sheets",
"tags": [],
"nodes": [
{
"id": "6680358c-de48-4459-aac7-dd7b903e542d",
"name": "When clicking ‘Test workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-1300,
340
],
"parameters": {},
"typeVersion": 1
},
{
"id": "896d5dcb-d2cf-4a86-8c84-7997bc7a2d0a",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1000,
40
],
"parameters": {
"width": 232,
"height": 346,
"content": "## Edit this node 👇
Change to the name of the company registered on Trustpilot and the maximum number of pages to scrape"
},
"typeVersion": 1
},
{
"id": "4d208d18-991b-4dfd-a717-8f752ea74a90",
"name": "Get reviews",
"type": "n8n-nodes-base.httpRequest",
"position": [
-700,
220
],
"parameters": {
"url": "=https://trustpilot.com/review/{{ $json.company_id }}",
"options": {
"pagination": {
"pagination": {
"parameters": {
"parameters": [
{
"name": "page",
"value": "={{ $pageCount + 1 }}"
}
]
},
"maxRequests": "={{ $json.max_page }}",
"requestInterval": 5000,
"limitPagesFetched": true,
"paginationCompleteWhen": "receiveSpecificStatusCodes",
"statusCodesWhenComplete": "404"
}
}
},
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "sort",
"value": "recency"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "b3e4c576-a9f4-48c8-ad27-696c0e0fc69d",
"name": "Global",
"type": "n8n-nodes-base.set",
"position": [
-960,
220
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "556e201d-242a-4c0e-bc13-787c2b60f800",
"name": "company_id",
"type": "string",
"value": "n8n.io"
},
{
"id": "a1f239df-df08-41d8-8b78-d6502266a581",
"name": "max_page",
"type": "number",
"value": 100
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f2dd1771-cba9-408f-93bd-2e83201edae9",
"name": "Parse reviews",
"type": "n8n-nodes-base.code",
"position": [
-480,
220
],
"parameters": {
"jsCode": "const cheerio = require('cheerio');
async function getReviewsFromPage(content) {
try {
const $ = cheerio.load(content);
const scriptTag = $('#__NEXT_DATA__');
if (!scriptTag.length) {
console.warn(\"Warning: Could not find review data in page\");
return [];
}
const reviewsRaw = JSON.parse(scriptTag.html());
return reviewsRaw.props.pageProps.reviews || [];
} catch (error) {
console.error(`Error fetching reviews: ${error.message}`);
return [];
}
}
async function scrapeTrustpilotReviews() {
let reviewsData = [];
for (let page = 0; page < $input.all().length; page++) {
console.log(`\nScraping page ${page}...`);
const content = $input.all()[page].json.data;
const reviews = await getReviewsFromPage(content);
if (!reviews.length) {
console.log(\"No more reviews found.\");
break;
}
console.log(`Found ${reviews.length} reviews on page ${page}`);
reviews.forEach(review => {
const data = {
Date: new Date(review.dates.publishedDate).toISOString().split('T')[0],
Author: review.consumer.displayName,
Body: review.text,
Heading: review.title,
Rating: review.rating,
Location: review.consumer.countryCode
};
reviewsData.push(review);
});
}
return reviewsData;
}
const reviews = await scrapeTrustpilotReviews();
return {reviews:reviews};"
},
"typeVersion": 2
},
{
"id": "b5204815-4feb-4311-a153-205933a325b2",
"name": "HelpfulCrowd edits",
"type": "n8n-nodes-base.set",
"position": [
-40,
460
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "e57e50a2-cf1c-4e9c-bcab-38c97ffc79d4",
"name": "product_id",
"type": "string",
"value": ""
},
{
"id": "acce9f30-1bae-4e75-9f96-a8590642e47c",
"name": "rating",
"type": "string",
"value": "={{ $json.rating }}"
},
{
"id": "6662028a-6c37-4a79-9d60-ea38d514b7b9",
"name": "title",
"type": "string",
"value": "={{ $json.title }}"
},
{
"id": "3bfe0ca5-d154-420f-8fbc-bd091472edb5",
"name": "feedback",
"type": "string",
"value": "={{ $json.text }}"
},
{
"id": "aa3e14f3-5f83-41fb-a2e2-fa8e2cfd74e6",
"name": "customer_name",
"type": "string",
"value": "={{ $json.consumer.displayName }}"
},
{
"id": "9048a66b-8c70-424f-a849-56f989be0b52",
"name": "customer_email",
"type": "string",
"value": ""
},
{
"id": "08cfc9c4-48fd-4ac7-ae4c-78bceaa3e745",
"name": "comment",
"type": "string",
"value": ""
},
{
"id": "90ec5664-4fcc-43d1-be72-144c3ea48475",
"name": "status",
"type": "string",
"value": "={{ $json.pending ? 'pending' : 'published' }}"
},
{
"id": "7076f725-b6c2-4c24-b517-c84f78ae69dc",
"name": "review_date",
"type": "string",
"value": "={{ $json.dates.publishedDate.split('T')[0] }}"
},
{
"id": "92c79888-dfb4-4be8-9f0d-c140a151ef0e",
"name": "verified",
"type": "string",
"value": "={{ $json.labels.verification.isVerified ? 'yes' : 'no' }}"
},
{
"id": "93e7b8b9-aea6-4ca4-bc7b-1e5469ddb39e",
"name": "media_1",
"type": "string",
"value": ""
},
{
"id": "5a2688d3-c9dd-4f5e-a975-f4357c752c95",
"name": "media_2",
"type": "string",
"value": ""
},
{
"id": "c6bbf887-bc47-4f9e-a3b0-bb6ba403b5b3",
"name": "media_3",
"type": "string",
"value": ""
},
{
"id": "218d7c77-44f1-4c22-a82c-8d7b49dcaf4a",
"name": "media_4",
"type": "string",
"value": ""
},
{
"id": "893356ab-fe8a-4500-be7b-d000fe78ebb7",
"name": "media_5",
"type": "string",
"value": ""
},
{
"id": "50355cf7-2d4d-49da-b62d-695916d9db77",
"name": "review_id",
"type": "string",
"value": "={{ $json.id }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "746bca7f-7d79-403b-b281-37c74db04b50",
"name": "Split Out",
"type": "n8n-nodes-base.splitOut",
"position": [
-260,
220
],
"parameters": {
"options": {},
"fieldToSplitOut": "reviews"
},
"typeVersion": 1
},
{
"id": "fc5aa26e-8b12-435b-8229-549c3034dc5b",
"name": "General edits",
"type": "n8n-nodes-base.set",
"position": [
-40,
-60
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "e57e50a2-cf1c-4e9c-bcab-38c97ffc79d4",
"name": "Date",
"type": "string",
"value": "={{ $json.dates.publishedDate }}"
},
{
"id": "fcbae9ed-47c4-4084-87b4-c8dac07396ba",
"name": "Author",
"type": "string",
"value": "={{ $('Parse reviews').item.json.reviews[0].consumer.displayName }}"
},
{
"id": "829a0a42-c7fb-4de2-9fa3-dd0c6dbf5624",
"name": "Body",
"type": "string",
"value": "={{ $json.text }}"
},
{
"id": "26c1bca9-b08c-43f7-90f9-eaa8b9666515",
"name": "Heading",
"type": "string",
"value": "={{ $json.title }}"
},
{
"id": "8855995e-f45d-4ae7-bd22-f9b406a16913",
"name": "Rating",
"type": "string",
"value": "={{ $json.rating }}"
},
{
"id": "bcf78f11-1c72-4305-9a02-fe2c937249f9",
"name": "Location",
"type": "string",
"value": "={{ $json.consumer.countryCode }}"
},
{
"id": "50355cf7-2d4d-49da-b62d-695916d9db77",
"name": "review_id",
"type": "string",
"value": "={{ $json.id }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "13f3720d-0753-49fc-a5e6-1473d5411e29",
"name": "General sheet",
"type": "n8n-nodes-base.googleSheets",
"position": [
360,
-60
],
"parameters": {
"columns": {
"value": {
"Body": "={{ $json.Body }}",
"Date": "={{ $json.Date }}",
"Author": "={{ $json.Author }}",
"Rating": "={{ $json.Rating }}",
"Heading": "={{ $json.Heading }}",
"Location": "={{ $json.Location }}",
"review_id": "={{ $json.review_id }}"
},
"schema": [
{
"id": "Date",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Author",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Author",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Body",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Body",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Heading",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Heading",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Rating",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Rating",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Location",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Location",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "review_id",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "review_id",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"review_id"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "appendOrUpdate",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 323953858,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1yf_RYZGFHpMyOvD3RKGSvIFY2vumvI4474Qm_1t4-jM/edit#gid=323953858",
"cachedResultName": "trustpilot"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1yf_RYZGFHpMyOvD3RKGSvIFY2vumvI4474Qm_1t4-jM",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1yf_RYZGFHpMyOvD3RKGSvIFY2vumvI4474Qm_1t4-jM/edit?usp=drivesdk",
"cachedResultName": "Squarespace automation"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "JgI9maibw5DnBXRP",
"name": "Google Sheets account"
}
},
"typeVersion": 4.5
},
{
"id": "0ffeed7c-7787-461f-a47b-704fa665dcc6",
"name": "HelpfulCrowd Sheets",
"type": "n8n-nodes-base.googleSheets",
"position": [
380,
460
],
"parameters": {
"columns": {
"value": {
"title": "={{ $('HelpfulCrowd edits').item.json.title }}",
"comment": "={{ $('HelpfulCrowd edits').item.json.comment }}",
"rating*": "={{ $('HelpfulCrowd edits').item.json.rating }}",
"status*": "={{ $('HelpfulCrowd edits').item.json.status }}",
"verified": "={{ $('HelpfulCrowd edits').item.json.verified }}",
"feedback*": "={{ $('HelpfulCrowd edits').item.json.feedback }}",
"review_id": "={{ $('HelpfulCrowd edits').item.json.review_id }}",
"product_id*": "={{ $('HelpfulCrowd edits').item.json.product_id }}",
"review_date*": "={{ $('HelpfulCrowd edits').item.json.review_date }}",
"customer_email": "={{ $('HelpfulCrowd edits').item.json.customer_email }}",
"customer_name*": "={{ $('HelpfulCrowd edits').item.json.customer_name }}"
},
"schema": [
{
"id": "product_id*",
"type": "string",
"display": true,
"required": false,
"displayName": "product_id*",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "rating*",
"type": "string",
"display": true,
"required": false,
"displayName": "rating*",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "title",
"type": "string",
"display": true,
"required": false,
"displayName": "title",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "feedback*",
"type": "string",
"display": true,
"required": false,
"displayName": "feedback*",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "customer_name*",
"type": "string",
"display": true,
"required": false,
"displayName": "customer_name*",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "customer_email",
"type": "string",
"display": true,
"required": false,
"displayName": "customer_email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "comment",
"type": "string",
"display": true,
"required": false,
"displayName": "comment",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "status*",
"type": "string",
"display": true,
"required": false,
"displayName": "status*",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "review_date*",
"type": "string",
"display": true,
"required": false,
"displayName": "review_date*",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "verified",
"type": "string",
"display": true,
"required": false,
"displayName": "verified",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "media_1",
"type": "string",
"display": true,
"required": false,
"displayName": "media_1",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "media_2",
"type": "string",
"display": true,
"required": false,
"displayName": "media_2",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "media_3",
"type": "string",
"display": true,
"required": false,
"displayName": "media_3",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "media_4",
"type": "string",
"display": true,
"required": false,
"displayName": "media_4",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "media_5",
"type": "string",
"display": true,
"required": false,
"displayName": "media_5",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "review_id",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "review_id",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"review_id"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "appendOrUpdate",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1811842087,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1yf_RYZGFHpMyOvD3RKGSvIFY2vumvI4474Qm_1t4-jM/edit#gid=1811842087",
"cachedResultName": "helpfulcrowd"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1yf_RYZGFHpMyOvD3RKGSvIFY2vumvI4474Qm_1t4-jM",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1yf_RYZGFHpMyOvD3RKGSvIFY2vumvI4474Qm_1t4-jM/edit?usp=drivesdk",
"cachedResultName": "Squarespace automation"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "JgI9maibw5DnBXRP",
"name": "Google Sheets account"
}
},
"typeVersion": 4.5
},
{
"id": "23f1b89f-ef06-4908-b00a-fa7b1f47b945",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
340,
80
],
"parameters": {
"width": 252,
"height": 166,
"content": "## Clone this spreadsheet
https://docs.google.com/spreadsheets/d/19nndnEO186vNmApxce8bA1AnLYrY8bR8VgYlwOU_FYA/edit?gid=0#gid=0"
},
"typeVersion": 1
},
{
"id": "2864095b-d6d5-4e58-bd33-0c0b0441df1e",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
340,
360
],
"parameters": {
"width": 252,
"height": 326,
"content": "### HelpfulCrowd column
Check this docs
https://www.guides.helpfulcrowd.com/en/article/import-product-reviews-wof0oy/"
},
"typeVersion": 1
},
{
"id": "d1f55902-441c-4658-ade9-033e89d9681b",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-1300,
120
],
"parameters": {
"rule": {
"interval": [
{}
]
}
},
"typeVersion": 1.2
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "a4b9bac7-f986-4744-9eeb-1e8faa1bab67",
"connections": {
"Global": {
"main": [
[
{
"node": "Get reviews",
"type": "main",
"index": 0
}
]
]
},
"Split Out": {
"main": [
[
{
"node": "HelpfulCrowd edits",
"type": "main",
"index": 0
},
{
"node": "General edits",
"type": "main",
"index": 0
}
]
]
},
"Get reviews": {
"main": [
[
{
"node": "Parse reviews",
"type": "main",
"index": 0
}
]
]
},
"General edits": {
"main": [
[
{
"node": "General sheet",
"type": "main",
"index": 0
}
]
]
},
"Parse reviews": {
"main": [
[
{
"node": "Split Out",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Global",
"type": "main",
"index": 0
}
]
]
},
"HelpfulCrowd edits": {
"main": [
[
{
"node": "HelpfulCrowd Sheets",
"type": "main",
"index": 0
}
]
]
},
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "Global",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Manualtrigger
- Stickynote
- Httprequest
- Set
- Code
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作